﻿namespace Calendar
{
    internal class Program
    {
        /// <summary>
        /// 打印日历
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //定义变量，从2022年第一天开始
            DateTime theDay = new DateTime(2022, 1, 1);
            //每月的高和宽
            int height = 9, width =45;
            int x=0, y=0,theDay_Week;
            //一天一天地循环，当前日期所在年份若超过2022年则终止
            for (;theDay.Year ==2022;theDay=theDay.AddDays (1))
            {
                //每月1号打印月份和星期
                if (theDay.Day == 1)
                {
                    x = ((theDay.Month-1) % 3) * width;
                    y = ((theDay.Month-1) / 3) * height;
                    Console.SetCursorPosition (x,y);
                    Console.Write($"        {theDay.Month}月");
                    Console.SetCursorPosition (x,++y);
                    Console.Write("日 一 二 三 四 五 六");
                    y++;
                }
                //获取当前日期对应星期几
                theDay_Week = Convert.ToInt32(theDay.DayOfWeek);
                Console.SetCursorPosition (x+theDay_Week*3,y);
                Console.Write($"{theDay.Day}  ");
                //打印完星期六后换行
                if (theDay_Week == 6)
                    y++;
            }
            Console.ReadKey();
        }
    }
}